﻿using System.Data;
using System.Data.SqlClient;

namespace nHydrate.EFCore.DataAccess
{
	public class DatabaseHelper
	{
		public static IDbCommand GetCommand(string commandText, CommandType commandType, IDbConnection connection)
		{
			var cmd = new SqlCommand(commandText);
			cmd.CommandType = commandType;
			cmd.Connection = (SqlConnection)connection;
			return cmd;
		}

		public static void AddParameter(IDbCommand cmd, string parameterName, object value)
		{
			var sqlParam = new SqlParameter(parameterName, value);
			cmd.Parameters.Add(sqlParam);
		}

		public static void AddReturnParameter(IDbCommand cmd)
		{
			var sqlParam = new SqlParameter();
			sqlParam.ParameterName = "@RETURN_VALUE";
			sqlParam.Direction = ParameterDirection.ReturnValue;
			cmd.Parameters.Add(sqlParam);
		}

	}
}
